var t = require("../../../../@babel/runtime/helpers/regeneratorRuntime"), e = require("../../../../@babel/runtime/helpers/asyncToGenerator"), i = require("../../../uv-ui-tools/libs/mixin/mpMixin.js"), n = require("../../../uv-ui-tools/libs/mixin/mixin.js"), o = require("./props.js"), r = require("../../../../common/vendor.js");

require("../../../uv-ui-tools/libs/function/index.js"), require("../../../uv-ui-tools/libs/function/test.js"), 
require("../../../uv-ui-tools/libs/function/digit.js"), require("../../../uv-ui-tools/libs/util/route.js"), 
require("../../../uv-ui-tools/libs/function/debounce.js"), require("../../../uv-ui-tools/libs/function/throttle.js");

var s = {
    name: "uv-index-list",
    mixins: [ i.mpMixin, n.mixin, o.props ],
    options: {
        virtualHost: !0
    },
    data: function() {
        return {
            activeIndex: -1,
            touchmoveIndex: 1,
            letterInfo: {
                height: 0,
                itemHeight: 0,
                top: 0
            },
            indicatorHeight: 50,
            touching: !1,
            scrollTop: 0,
            scrollViewHeight: 0,
            sys: "",
            scrolling: !1,
            scrollIntoView: "",
            hasHeight: 0,
            timer: 0,
            disTap: !1
        };
    },
    computed: {
        uIndexList: function() {
            return this.indexList.length ? this.indexList : function() {
                for (var t = [], e = "A".charCodeAt(0), i = 0; i < 26; i++) t.push(String.fromCharCode(e + i));
                return t;
            }();
        },
        indicatorTop: function() {
            var t = this.letterInfo, e = t.top, i = t.itemHeight;
            return Math.floor(e + i * this.activeIndex + i / 2 - this.indicatorHeight / 2) - 8;
        }
    },
    watch: {
        uIndexList: {
            immediate: !0,
            handler: function() {
                var t = this;
                this.$uv.sleep().then(function() {
                    t.setIndexListLetterInfo();
                });
            }
        }
    },
    created: function() {
        this.sys = this.$uv.sys(), this.children = [], this.anchors = [], this.init();
    },
    mounted: function() {
        this.setIndexListLetterInfo();
    },
    methods: {
        init: function() {
            this.scrollViewHeight = this.sys.windowHeight - this.$uv.getPx(this.customNavHeight);
        },
        touchStart: function(t) {
            var e = t.changedTouches[0];
            if (e && !this.disTap) {
                this.touching = !0;
                var i = e.pageY, n = this.getIndexListLetter(i);
                this.setValueForTouch(n);
            }
        },
        touchMove: function(t) {
            var e = t.changedTouches[0];
            if (e && !this.disTap) {
                this.touching || (this.touching = !0);
                var i = e.pageY, n = this.getIndexListLetter(i);
                this.setValueForTouch(n);
            }
        },
        touchEnd: function(t) {
            var e = this;
            this.$uv.sleep(300).then(function() {
                e.touching = !1;
            }), this.$emit("select", this.activeIndex);
        },
        getIndexListLetterRect: function() {
            var t = this;
            return new Promise(function(e) {
                t.$uvGetRect(".uv-index-list__letter").then(function(t) {
                    e(t);
                });
            });
        },
        setIndexListLetterInfo: function() {
            var t = this;
            this.getIndexListLetterRect().then(function(e) {
                e.top;
                var i, n = e.height, o = t.$uv.sys().windowHeight;
                i = 0 == t.customNavHeight ? 0 : t.$uv.getPx(t.customNavHeight), t.letterInfo = {
                    height: n,
                    top: (o - n) / 2 + i / 2,
                    itemHeight: Math.floor(n / t.uIndexList.length)
                };
            });
        },
        getIndexListLetter: function(t) {
            var e = this.letterInfo, i = e.top, n = e.height, o = e.itemHeight;
            return t < i ? 0 : t >= i + n ? this.uIndexList.length - 1 : Math.floor((t - i) / o);
        },
        setValueForTouch: function(t) {
            t !== this.activeIndex && (this.activeIndex = t, this.scrollTop = this.children[t].top);
        },
        getHeaderRect: function() {
            var t = this;
            return new Promise(function(e) {
                dom.getComponentRect(t.$refs.header, function(t) {
                    e(t.size);
                });
            });
        },
        scrollHandler: function(i) {
            var n = this;
            return e(t().mark(function e() {
                var o, r, s, u, c, h, a;
                return t().wrap(function(t) {
                    for (;;) switch (t.prev = t.next) {
                      case 0:
                        if (!n.touching && !n.scrolling) {
                            t.next = 2;
                            break;
                        }
                        return t.abrupt("return");

                      case 2:
                        n.scrolling = !0, n.disTap = !0, clearTimeout(n.timer), n.timer = setTimeout(function() {
                            n.disTap = !1;
                        }, 200), n.$uv.sleep(30).then(function() {
                            n.scrolling = !1;
                        }), o = 0, r = n.children.length, s = n.children, n.anchors, u = n.$uv.getPx(n.customNavHeight), 
                        o = i.detail.scrollTop, c = 0;

                      case 10:
                        if (!(c < r)) {
                            t.next = 24;
                            break;
                        }
                        if (h = s[c], a = s[c + 1], !(o + u <= s[0].top || o >= s[r - 1].top + s[r - 1].height)) {
                            t.next = 15;
                            break;
                        }
                        return n.activeIndex = -1, t.abrupt("break", 24);

                      case 15:
                        if (a) {
                            t.next = 18;
                            break;
                        }
                        return n.activeIndex = r - 1, t.abrupt("break", 24);

                      case 18:
                        if (!(o + u > h.top && o + u < a.top)) {
                            t.next = 21;
                            break;
                        }
                        return n.activeIndex = c, t.abrupt("break", 24);

                      case 21:
                        c++, t.next = 10;
                        break;

                      case 24:
                      case "end":
                        return t.stop();
                    }
                }, e);
            }))();
        }
    }
};

Array || r.resolveComponent("uv-transition")(), Math;

var u = r._export_sfc(s, [ [ "render", function(t, e, i, n, o, s) {
    return {
        a: o.scrollTop,
        b: o.scrollIntoView,
        c: t.$uv.addUnit(o.scrollViewHeight, "px"),
        d: r.o(function() {
            return s.scrollHandler && s.scrollHandler.apply(s, arguments);
        }),
        e: r.f(s.uIndexList, function(e, i, n) {
            return {
                a: r.t(e),
                b: o.activeIndex === i ? "#fff" : t.inactiveColor,
                c: i,
                d: o.activeIndex === i ? t.activeColor : "transparent"
            };
        }),
        f: t.$uv.addUnit(o.letterInfo.top || 100, "px"),
        g: r.o(function() {
            return s.touchStart && s.touchStart.apply(s, arguments);
        }),
        h: r.o(function() {
            return s.touchMove && s.touchMove.apply(s, arguments);
        }),
        i: r.o(function() {
            return s.touchEnd && s.touchEnd.apply(s, arguments);
        }),
        j: r.o(function() {
            return s.touchEnd && s.touchEnd.apply(s, arguments);
        }),
        k: r.t(s.uIndexList[o.activeIndex]),
        l: t.$uv.addUnit(o.indicatorHeight, "px"),
        m: t.$uv.addUnit(o.indicatorHeight, "px"),
        n: r.p({
            mode: "fade",
            show: o.touching,
            customStyle: {
                position: "fixed",
                right: "40px",
                top: t.$uv.addUnit(s.indicatorTop, "px"),
                zIndex: 2
            }
        })
    };
} ], [ "__scopeId", "data-v-b64e5079" ] ]);

wx.createComponent(u);